$(function () {
        //页面加载完成获取第一页数据
    getExpruleList(1);
    $('body').on('click','.updateStatus',function () {
        var status= $(this).data("status");
        var userExpruleId=$(this).data("id");
        var obj =$(this);
        if(status==3){
            icModale(2,"删除后不可恢复，确认删除么？",0,function () {
                updateUserExpruleStatus(userExpruleId,status,obj);
            });
        }else if(status==2){
            icModale(2,"确认冻结停用？",0,function () {
                updateUserExpruleStatus(userExpruleId,status,obj);
            });
        }
        else if(status==1){
            icModale(2,"确认回复么？",0,function () {
                updateUserExpruleStatus(userExpruleId,status,obj);
            });
        }
    });

    //表格中单个字段的修改
    $('body').on('click', '.resetdBtn', function() {
        var  score  =$(this).data('score');
        var   id = $(this).data('id');
        var index = parent.layer.open({
            type: 1,
            area: ['380px'],
            skin: 'layui-layer-demo',
            title: '修改此项',
            content: '<div class="m-t m-r m-l m-b"><input class="form-control" value="'+score+'" id="userExpruleScore" name="userExprule.score" type="text"></div>',
            btn: '确定',
            yes: function(index, layero) {
                var userExpruleScore = layero.find('#userExpruleScore').val();
                $.ajax({
                    url:baseloaction+"/admin/user/cus/updateUserExprule",
                    type:"post",
                    data:{"id":id,"score":userExpruleScore},
                    dataType:"json",
                    success:function (result) {
                        console.log(result);
                        parent.layer.close(index);
                        if (result.success == true) {
                            icModale(0,result.message);
                            $('.userExpruleScore_'+id).html(userExpruleScore);
                            $('.userExpruleScore_'+id).append('<span class="resetdBtn fs16 c-red" data-id="'+id+'"  data-score="'+userExpruleScore+'" title="修改"><i class="fa fa-pencil"></i></span>');
                        } else {
                            icModale(0,result.message);
                        }
                    },
                    error:function (error) {
                        parent.layer.close(index);
                        icModale(0,'系统繁忙，经验数额修改失败');
                    }
                });
            }
        });
    });
});
function updateUserExpruleStatus(userExpruleId,status,obj) {
    $.ajax({
        url: baseloaction+"/admin/user/cus/updateCusUserExpruleStatus",
        type: 'post',
        dataType: 'json',
        data: {"id":userExpruleId,"status":status},
        success: function (result) {
            if (result.success == true) {
                icModale(1,result.message,1,function () {
                  if(status==1){
                      obj.data('status','2');
                      obj.attr('data-original-title','停用');
                      obj.html('<i class="fa fa-unlock-alt"></i>');
                      $('.userExpruleStatus_'+userExpruleId).html('<span class="label label-info">正常</span>')
                  }else if(status==2){
                      obj.data('status','1');
                      obj.attr('data-original-title','回复');
                      obj.html('<i class="fa fa-history"></i>');
                      $('.userExpruleStatus_'+userExpruleId).html('<span class="label label-danger">停用</span>')
                  }else if (status==3){
                      obj.parents('tr').remove();
                      var totalCountNum =$('#totalCountNum').val();
                      $("#totalCountNum").val((totalCountNum - 1));
                      if((totalCountNum-1)==0){
                          $("#tbodyExprule").append('<td colspan="6" class="text-center">'
                              +'<div class="noDataTipsBox">'
                              +'<p><span class="c-4e fs16">亲，还没有数据~~~</span></p>'
                              +'</div>'
                              +'</td>'
                          );
                      }
                  }
                });
            } else {
                icModale(0,result.message);
            }
        }
    })

}
/**
 * 获取角色列表页面
 * @param pageNo 当前页码
 */
function getExpruleList(pageNo) {
    var params = '{}';
    var obj = {
        url: baseloaction + '/admin/user/cus/ajaxUserExpruleList',//请求URL
        contextId:'exprule-list-context',//响应内容页面设置内容ID
        params:params,//请求参数
        pageNo:pageNo,//页码
        pageCall:getExpruleList, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
        selectAllId:'select-all-role', //全选框ID
        callback:function () {//数据加载完成回调

        }
    };
    ajaxGetListData(obj)
}
